//
//  SISSCoopCommentMidView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/28.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCoopCommentMidView.h"
#import "SISSRateBarView.h"

@interface SISSCoopCommentMidView ()<SISSRateBarViewDelegate>

/// 房屋信息真实度Label
@property (weak, nonatomic) UILabel *validityLabel;
/// 服务态度满意度Label
@property (weak, nonatomic) UILabel *satisfyLabel;
/// 业务水平专业度Label
@property (weak, nonatomic) UILabel *businessLevelLabel;
/// 房屋信息真实度StarView
@property (weak, nonatomic) SISSRateBarView *validityStarView;
/// 服务态度满意度StarView
@property (weak, nonatomic) SISSRateBarView *satisfyStarView;
/// 业务水平专业度StarView
@property (weak, nonatomic) SISSRateBarView *businessLevelStarView;

/// 评语Label
@property (weak, nonatomic) UILabel *commentLabel;




@end
@implementation SISSCoopCommentMidView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self initUI];
        [self initConstraint];
    }
    
    return self;
}

#pragma mark - SISSRateBarViewDelegate
- (void)rateBarViewDidSelectedRateBarView:(SISSRateBarView *)rateBarView atIndex:(NSInteger)index {
    rateBarView.rate = index;
    switch (rateBarView.tag) {
        case 100:
            self.validityStar = index;
            break;
            
        case 101:
            self.satisfyStar = index;
            break;
            
        case 102:
            self.businessLevelStar = index;
            break;
            
        default:
            break;
    }
}

#pragma mark - UI
- (void)initUI {
    
    UILabel *validityLabel = [[UILabel alloc] init];
    validityLabel.font = [UIFont systemFontOfSize:16];
    validityLabel.textColor = MAIN_TEXT_COLOR;
    validityLabel.text = @"房屋信息真实度：";
    [self addSubview:validityLabel];
    self.validityLabel = validityLabel;
    
    SISSRateBarView *validityView = [[SISSRateBarView alloc] init];
    validityView.delegate = self;
    validityView.starTintColor = [UIColor redColor];
    validityView.tag = 100;
    [self addSubview:validityView];
    self.validityStarView = validityView;
    
    UILabel *satisfyLabel = [[UILabel alloc] init];
    satisfyLabel.font = [UIFont systemFontOfSize:16];
    satisfyLabel.textColor = MAIN_TEXT_COLOR;
    satisfyLabel.text = @"服务态度满意度：";
    [self addSubview:satisfyLabel];
    self.satisfyLabel = satisfyLabel;
    
    SISSRateBarView *satisfyStarView = [[SISSRateBarView alloc] init];
    satisfyStarView.delegate = self;
    satisfyStarView.starTintColor = [UIColor redColor];
    satisfyStarView.tag = 101;
    [self addSubview:satisfyStarView];
    self.satisfyStarView = satisfyStarView;
    
    UILabel *businessLevelLabel = [[UILabel alloc] init];
    businessLevelLabel.font = [UIFont systemFontOfSize:16];
    businessLevelLabel.textColor = MAIN_TEXT_COLOR;
    businessLevelLabel.text = @"业务水平专业度：";
    [self addSubview:businessLevelLabel];
    self.businessLevelLabel = businessLevelLabel;
    
    SISSRateBarView *businessLevelStarView = [[SISSRateBarView alloc] init];
    businessLevelStarView.delegate = self;
    businessLevelStarView.starTintColor = [UIColor redColor];
    businessLevelStarView.tag = 102;
    [self addSubview:businessLevelStarView];
    self.businessLevelStarView = businessLevelStarView;
    
    UILabel *commentLabel = [[UILabel alloc] init];
    commentLabel.font = [UIFont systemFontOfSize:16];
    commentLabel.textColor = MAIN_TEXT_COLOR;
    commentLabel.text = @"评语：";
    [self addSubview:commentLabel];
    self.commentLabel = commentLabel;
    
    SISSTextView *commentTextView = [[SISSTextView alloc] init];
    commentTextView.layer.borderWidth = 1;
    commentTextView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    commentTextView.placeholder = @"请输入评价，不要包含特殊字符。";
    [self addSubview:commentTextView];
    self.commentTextView = commentTextView;

}

#pragma mark - 约束
- (void)initConstraint {
    
    WeakSelf
    CGFloat margin = 8.0;
    [self.validityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(2 * margin);
        make.top.equalTo(weakSelf).offset(2 * margin);
    }];
    
    [self.validityStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityLabel.mas_right);
        make.centerY.equalTo(weakSelf.validityLabel);
        make.size.mas_equalTo(CGSizeMake(200, 30));
    }];
    
    [self.satisfyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityLabel);
        make.top.equalTo(weakSelf.validityLabel.mas_bottom).offset(margin);
    }];
    
    [self.satisfyStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.validityStarView);
        make.centerY.equalTo(weakSelf.satisfyLabel);
        make.size.equalTo(weakSelf.validityStarView);
    }];
    
    [self.businessLevelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.satisfyLabel);
        make.top.equalTo(weakSelf.satisfyLabel.mas_bottom).offset(margin);
    }];
    
    [self.businessLevelStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.satisfyStarView);
        make.centerY.equalTo(weakSelf.businessLevelLabel);
        make.size.equalTo(weakSelf.satisfyStarView);
    }];
    
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.businessLevelLabel);
        make.top.equalTo(weakSelf.businessLevelLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.commentLabel);
        make.top.equalTo(weakSelf.commentLabel.mas_bottom);
        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.height.mas_equalTo(10 * margin);
        make.bottom.equalTo(weakSelf);
    }];

}

@end
